function openRouter ({ query = {}, name = '', type = '' } = {}) {
  let params = ''
  const formatQuery = query => {
    let params = ''
    if (query) {
      for (const item in query) {
        const vals = query[item]

        if (vals !== undefined) {
          params += item + '=' + vals + '&'
        }
      }
    }
    params = params ? '?' + params : params
    return params
  }

  if (query) {
    params = formatQuery(query)
  }

  const protocol = location.protocol
  const host = location.host
  const currentUrl = protocol + '//' + host

  // const homepath = `/${location.pathname.split('/')[1]}/` // 获取单页前缀

  const ENV = import.meta.env
  const isDev = ENV.MODE === 'development' ? true : false
  let pageName = ''
  if (name && typeof name === 'string' && name != '/') {
    pageName = isDev ? name + '/index.html' : name
  }
  const url = `${currentUrl}${import.meta.env.BASE_URL}${pageName}${params}` // 拼接url
  setTimeout(() => {
    if (type === 'replace') {
      location.replace(url) // replace 跳转
    } else {
      location.href = url // href 跳转
    }
  }, 10)
}

export default {
  install(app, options) {
    app.config.globalProperties.$openRouter = openRouter
  }
}
